package com.liucxu.zimuzu.View.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.liucxu.zimuzu.Model.Bean.HotEntity;
import com.liucxu.zimuzu.R;
import com.liucxu.zimuzu.Utils.DisplayUtil;
import com.liucxu.zimuzu.Utils.GlideUtils;
import com.liucxu.zimuzu.Utils.RandomColorUtils;
import com.liucxu.zimuzu.Utils.ViewHolderUtils;
import com.orhanobut.logger.Logger;

import java.util.ArrayList;
import java.util.List;

/**
 * 今日热点Adapter
 * Created by liukanshan on 2016/12/9.
 */

public class HotAdapter extends BaseAdapter {

    private ArrayList<HotEntity> data = new ArrayList<>();
    private Context mContext;
    private String randomColor = RandomColorUtils.RandomColor();

    public HotAdapter(Context context, ArrayList<HotEntity> datas) {
        this.mContext = context;
        if (datas != null) {
            data.clear();
            data.addAll(datas);
        }
    }

    public void setData(List<HotEntity> datas) {
        if (datas != null) {
            data.clear();
            data.addAll(datas);
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.adapter_hot, null);
        }
        initViews(position, convertView);
        return convertView;
    }

    private void initViews(final int position, View convertView) {
        HotEntity hotEntity = data.get(position);
        RelativeLayout card_content_rl = ViewHolderUtils.get(convertView, R.id.card_content_rl);
        ImageView adapter_hot_imager = ViewHolderUtils.get(convertView, R.id.adapter_hot_imager);
        TextView adapter_hot_title = ViewHolderUtils.get(convertView, R.id.adapter_hot_title);
        GlideUtils.getInstance().LoadSimpleContextRoundBitmap(mContext,hotEntity.getPoster(),adapter_hot_imager, DisplayUtil.px2dip(mContext,14));
        adapter_hot_title.setText(hotEntity.getCnname());
        Logger.d(randomColor);
//        card_content_rl.setBackgroundColor(Color.parseColor("#00796B"));


        TextView adapter_en_name = ViewHolderUtils.get(convertView, R.id.adapter_en_name);
        adapter_en_name.setText("频道：" + hotEntity.getChannel());
        TextView resource_desc = ViewHolderUtils.get(convertView, R.id.resource_desc);
        resource_desc.setText("说明：" + hotEntity.getPlay_status());
        TextView resource_type = ViewHolderUtils.get(convertView, R.id.resource_type);
        resource_type.setText("类型：" + hotEntity.getCategory());
        TextView resource_score = ViewHolderUtils.get(convertView, R.id.resource_score);
        resource_score.setText("地区：" + hotEntity.getArea());

        //点击事件，不好意思写在这个地方
        card_content_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
    }
}
